﻿using System;
using Microsoft.SPOT;
using Gadgeteer.Interfaces.Temp;

namespace Gadgeteer.Interfaces.GTM.Seed.TemperatureHumidity
{
    internal class TemperatureHumidityWrapper : ITemperatureHumidity
    {
        private readonly Gadgeteer.Modules.Seeed.TemperatureHumidity sensorModule;

        internal TemperatureHumidityWrapper(Gadgeteer.Modules.Seeed.TemperatureHumidity sensorModule)
        {
            if (sensorModule == null) throw new ArgumentNullException("sensorModule");
            this.sensorModule = sensorModule;
        }

        public event TemperatureMeasurementEventHandler TemperatureMeasured;

        private void OnTempratureMeasured(double temperature)
        {
            var ev = TemperatureMeasured;
            if (ev != null)
            {
                ev(this, temperature);
            }
        }

        public event HumidityMeasurementEventHandler HumidityMeasured;

        private void OnHumidityMeasured(double humidity)
        {
            var ev = HumidityMeasured;
            if (ev != null)
            {
                ev(this, humidity);
            }
        }

        public void RequestMeasurement()
        {
            sensorModule.RequestMeasurement();
        }

        public void StartContinuousMeasurements()
        {
            sensorModule.StartContinuousMeasurements();
        }

        public void StopContinuousMeasurements()
        {
            sensorModule.StopContinuousMeasurements();
        }
    }
}
